<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/commons/taglibs.jsp" %>
<!DOCTYPE html>
<html>
<%@ include file="/commons/head.jsp" %>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <%@ include file="/commons/left.jsp" %>
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                公告列表
            </h1>
            <section class="content">
                <div class="row">
                    <div class="col-xs-12">
                        <div class="box">
                            <div class="box-header">
                                <div class="input_box col-sm-5 margin">
                                    <form  name="searchForm" id="searchForm"
                                          action="${ctx}/announce/listAnnounce" method="get">
                                        <input type="hidden" id="pageNum" name="pageNum" value="1" />
                                        <input type="hidden" id="length" name="length" value="10" />
                                        <label style=" float: left; height: 26px; line-height: 25px;">公告状态：</label>
                                        <div class="input" style="float: left;">
                                            <select name="isStatis" style="height: 26px;margin: 0 15px;">
                                                <option value="1">发布</option>
                                                <option value="0" selected="selected">未发布</option>
                                            </select>
                                        </div>
                                        <div class="input_btn" style=" float: left;">
                                            <input type="submit" value="查询">
                                        </div>
                                    </form>
                                </div>
                                <div class="margin" style="float:right;">
                                    <button type="button" class="btn btn-default" onclick="window.location.href='${ctx}/announce/editAnnounce?action=add'"><span
                                            class="glyphicon glyphicon-plus"></span> 新增
                                    </button>
                                </div>
                            </div>
                            <div class="box-body">
                                <table id="example2" class="table table-bordered table-hover">
                                    <thead>
                                    <tr>
                                        <th>标题</th>
                                        <th>显示位置</th>
                                        <th class="time">创建时间</th>
                                        <th>状态</th>
                                        <th>操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <c:if test="${page.maxRow > 0}">
                                        <c:forEach var="item" items="${listAnnounce}" varStatus="vs">
                                            <tr>
                                                <td>${item.title}</td>
                                                <td>${item.displayPorition}</td>
                                                <td><fmt:formatDate pattern="yyyy-MM-dd HH:mm:ss" value="${item.createTime}"></fmt:formatDate></td>
                                                <c:if test="${item.isStatis==0}">
                                                    <td><span class="red">未发布</span></td>
                                                    <td><a onclick="statusEnabled('${item.id}',1)"
                                                           data-able="1">发布</a><em></em><a
                                                            onclick="openAnnounceEdit('${item.id}')">修改</a><em></em><a
                                                            onclick="deleteAnnounce('${item.id}')">删除</a></td>
                                                </c:if>
                                                <c:if test="${item.isStatis==1}">
                                                    <td><span class="green">发布</span></td>
                                                    <td><a onclick="statusEnabled('${item.id}',0)"
                                                           data-able="0">取消发布</a><em></em><a
                                                            onclick="openAnnounceEdit('${item.id}')">修改</a><em></em><a
                                                            onclick="deleteAnnounce('${item.id}')">删除</a></td>
                                                </c:if>
                                            </tr>
                                        </c:forEach>
                                    </c:if>
                                    </tbody>
                                </table>
                                <div>
                                    <jsp:include page="/commons/pagination.jsp"/>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </section>
        </section>

    </div>
    <%@ include file="/commons/script.jsp" %>
    <script type="text/javascript">
        function openAnnounceEdit(id) {
            window.location.href='${ctx}/announce/editAnnounce?action=update&id='+id;
        }
        function deleteAnnounce(id) {
            $.ajax({
                type: "POST",
                url: "${ctx}/announce/deleteAnnounce",
                data: { id: id},
                success: function (e) {
                    if (e==1) {
                        alert("删除成功!");
                        window.location.reload();
                    }
                    else {
                        alert("删除失败！");
                        window.location.reload();
                    }
                    return;
                },
                error: function (msg) {
                    alert("系统发生错误，请稍后再试！");
                    window.location.reload();
                }
            });
        }
    </script>
</body>
</html>







